<script setup>
import axios from 'axios'
import { ref, onMounted } from 'vue'
// TODO: 编辑

// 弹框开关
let dialogVisible = ref(false)
let editForm = ref(null)
const open = (row) => {
  // 获取当前数据
  editForm.value = row;
  // 打开遮罩层
  dialogVisible.value = true
}
// 抛出子组件的函数
defineExpose({
  open
})
// ----------点击确定 实现修改----------------
const confirmEdit = async () => {
  let {data} = await axios.patch(`/edit/${editForm.value.id}`, {
    name: editForm.value.name,
    place: editForm.value.place,
  })
  // 如果编辑成功 则  关闭弹框
  if(data.success) dialogVisible.value = false
}
</script>

<template>
  <el-dialog v-model="dialogVisible" title="编辑" width="400px">
    <el-form label-width="50px" :form="editForm">
      <el-form-item label="姓名">
        <el-input placeholder="请输入姓名" v-model="editForm.name" />
      </el-form-item>
      <el-form-item label="籍贯">
        <el-input placeholder="请输入籍贯" v-model="editForm.place" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmEdit">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.el-input {
  width: 290px;
}
</style>
